home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / turbovis / ansiview.zip / ANSIVIEW.PAS < prev    next >
Pascal/Delphi Source File  |  1991-01-30  |  22KB  |  743 lines

  1. Unit AnsiView;
  2.  
  3. {     ANSIVIEW.PAS - 24 January 1991
  4.  
  5.                           By Marcos R. Della
  6.                              5084 Rincon Ave.
  7.                              Santa Rosa, CA 95409
  8.  
  9.                              CIS: 71675,765
  10.  
  11.       This Unit was written so that I had something that reminded me of the
  12.       original WRITELN and WRITE statments of pascal where I was working
  13.       with the screen and there were various definate controls I had using
  14.       the GOTOXY and CLRSCR routines.  Under TVision, you no longer have
  15.       these controls and need to learn a completely different way of getting
  16.       info on the screen.
  17.  
  18.       AnsiView was written to give you some of these old methods while still
  19.       using the TVision platform. That is, your screen is a scroll window of
  20.       your size choosing (You can define a screen 128,2048 and use the gotoxy
  21.       to get to anywhere on that screen!)  Also if you turn on the ANSI
  22.       option, the driver will recognise ANSI controls (For reading those ANSI
  23.       files directly and displaying them!)
  24.  
  25.       Because this is also a TVision enviroment, your screen will also be
  26.       saved if you do a desktop save! Wonderful stuff eh?
  27.  
  28.  
  29.       NOTE!!!   Registration values used by this Unit
  30.  
  31.                     TANSIView = 7200;
  32.                     TInterior = 7201;
  33.  
  34.       --------------------
  35.       Modification History
  36.       --------------------
  37.  
  38.       29 January 1991 - Added the code to handle 15 of the ANSI control
  39.                         characters if they are passed to the ANSIView
  40.       routines.  There are two commands that will no work with this current
  41.       implementation. The <ESC>[xP and <ESC>[x@ for insert and delete
  42.       characters on the current line.  These should be supported in the
  43.       near future whenever I get back to working on this unit...
  44.  
  45.       There is a problem with the cursor positioning not always updating
  46.       the onscreen cursor display (if you have it on) however with the
  47.       printing of any character or other command, it comes back on. I'm
  48.       still scratching my head over this one.
  49.  
  50.       30 January 1991 - I know, I'm making too many changes... Oh well...
  51.                         Anyway, the code has been added for the insert and
  52.       delete characters on the line.  Turned out to be easier than I thought.
  53.       Also some redundant .DrawViews were removed to help speed up the
  54.       execution.  If only I could figure out Turbo Profiler...
  55.       NOTE:  There are a few ANSI sequences that are related to the keyboard
  56.       handler and cursor request.  These are coded into the system so that
  57.       they do not produce display errors, however the code does nothing other
  58.       than strip out the sequences from the display.
  59.  
  60. }
  61.  
  62. {$DEFINE ANSICOMPAT} { Define this if you want the code compiled that will
  63.                        allow you to have ANSI compatability. If you have no
  64.                        use for the ANSI routines, feel free to undefine this
  65.                        and save a little code space... (Around 2.2k) }
  66.  
  67. {$F+,O+,R-,S-}
  68.  
  69. Interface
  70.  
  71. Uses Dos, Drivers, Views, Objects, Memory;
  72.  
  73. CONST MaxViewHeight = 2048;
  74.       MaxParms      = 5;     {If you can't do it in 5 ANSI parms...}
  75.  
  76. TYPE  PScreenL  = ^TScreenL;
  77.       TScreenL  = ARRAY[0..MaxViewWidth - 1] OF WORD;
  78.  
  79.       PScreenR  = ^TScreenR;
  80.       TScreenR  = ARRAY[0..MaxViewHeight - 1] OF PScreenL;
  81.  
  82.       PInterior = ^TInterior;
  83.       TInterior = OBJECT(TScroller)
  84.                      AutoScroll : BOOLEAN;
  85.                      MaxDim     : TPoint;
  86.                      CurLoc     : TPoint;
  87.                      TopPtr     : PScreenR;
  88.                      CONSTRUCTOR Init(VAR Bounds : TRect; Limits : TPoint;
  89.                                           Color : BYTE; AHScrollBar, AVScrollBar : PScrollBar);
  90.                      CONSTRUCTOR Load(VAR S : TStream);
  91.                      PROCEDURE Store(VAR S : TStream);
  92.                      PROCEDURE Draw; VIRTUAL;
  93.                      PROCEDURE PrintChar(Ch : CHAR; VAR TextAttr : BYTE);
  94.                      DESTRUCTOR Done; VIRTUAL;
  95.                   END;
  96.  
  97.       ParmsFld  = ARRAY[1..MaxParms] OF BYTE;
  98.  
  99.       PANSIView = ^TANSIView;
  100.       TANSIView = OBJECT(TWindow)
  101.                      UseANSI    : BOOLEAN;
  102.                      CurHold    : TPoint;
  103.                      EndString  : CHAR;
  104.                      ESCBuf     : STRING[MaxParms * 3 + 4];
  105.                                                {Max needed since we do not
  106.                                                 support string redifinition}
  107.                      ParmsIdx   : BYTE;
  108.                      StateInfo  : BYTE;
  109.                      ANSIParms  : ParmsFld;
  110.                      TextAttr   : BYTE;
  111.                      Interior   : PInterior;
  112.                      CONSTRUCTOR Init(Bounds : TRect; Limits : TPoint; WnTitle : STRING; WindowNo : WORD);
  113.                      CONSTRUCTOR Load(VAR S : TStream);
  114.                      PROCEDURE Store(VAR S : TStream);
  115.                      FUNCTION  ProcessChar(Ch : CHAR) : BOOLEAN;
  116.  
  117.                      PROCEDURE PrintLN(s : STRING);
  118.                      PROCEDURE Print(s : STRING);
  119.                      PROCEDURE PrintChar(Ch : CHAR);
  120.                      PROCEDURE PutChar(X, Y : WORD; Ch : CHAR; Attr : BYTE);
  121.  
  122.                      PROCEDURE CursorOn;
  123.                      PROCEDURE CursorOff;
  124.                      PROCEDURE AutoScrollOn;
  125.                      PROCEDURE AutoScrollOff;
  126.  
  127.                      PROCEDURE ClrScr;
  128.                      PROCEDURE ClrEol;
  129.                      PROCEDURE DelLine;
  130.                      PROCEDURE GotoXY(X,Y : WORD);
  131.                      PROCEDURE HighVideo;
  132.                      PROCEDURE InsLine;
  133.                      PROCEDURE LowVideo;
  134.                      PROCEDURE TextBackground(Color : BYTE);
  135.                      PROCEDURE TextColor(Color : BYTE);
  136.                      FUNCTION WhereX : BYTE;
  137.                      FUNCTION WhereY : WORD;
  138.                   END;
  139.  
  140. CONST RANSIView: TStreamRec = (
  141.          ObjType: 7200;
  142.          VmtLink: Ofs(TypeOf(TANSIView)^);
  143.          Load:    @TANSIView.Load;
  144.          Store:   @TANSIView.Store
  145.       );
  146.  
  147.       RInterior: TStreamRec = (
  148.          ObjType: 7201;
  149.          VmtLink: Ofs(TypeOf(TInterior)^);
  150.          Load:    @TInterior.Load;
  151.          Store:   @TInterior.Store
  152.       );
  153.  
  154. PROCEDURE RegisterANSIView;
  155.  
  156. Implementation
  157.  
  158. {----------------------------------------------------------------------------}
  159.  
  160. FUNCTION Min(X,Y : INTEGER) : INTEGER; ASSEMBLER;
  161. ASM
  162.    MOV   AX,X
  163.    CMP   AX,Y
  164.    JLE   @@1
  165.    MOV   AX,Y
  166. @@1:
  167. END;
  168.  
  169. FUNCTION Max(X,Y : INTEGER) : INTEGER; ASSEMBLER;
  170. ASM
  171.    MOV   AX,X
  172.    CMP   AX,Y
  173.    JGE   @@1
  174.    MOV   AX,Y
  175. @@1:
  176. END;
  177.  
  178. {----------------------------------------------------------------------------}
  179.  
  180. CONSTRUCTOR TInterior.Init;
  181. VAR   i,j : WORD;
  182. BEGIN
  183.    TScroller.Init(Bounds,AHScrollBar,AVScrollBar);
  184.    MaxDim     := Limits;
  185.    AutoScroll := TRUE;
  186.    CurLoc.X   := 0;
  187.    CurLoc.Y   := 0;
  188.    TopPtr := MemAlloc(MaxDim.Y * SIZEOF(PScreenR));     {Allocate All Y Coords}
  189.    IF TopPtr = NIL THEN
  190.       BEGIN
  191.          TScroller.Done;
  192.          FAIL
  193.       END;
  194.    FOR i := 0 TO MaxDim.Y - 1 DO BEGIN                  {Now for each line}
  195.       TopPtr^[i] := MemAlloc(MaxDim.X * SIZEOF(WORD));
  196.       IF TopPtr^[i] = NIL THEN
  197.          BEGIN
  198.             IF i > 0 THEN
  199.                FOR j := 0 TO i - 1 DO
  200.                   FREEMEM(TopPtr^[j],MaxDim.X * SIZEOF(WORD));
  201.             FREEMEM(TopPtr,MaxDim.Y * SIZEOF(PScreenR));
  202.             TScroller.Done;
  203.             FAIL
  204.          END
  205.       ELSE
  206.          MoveChar(TopPtr^[i]^,' ',Color,MaxDim.X)
  207.    END;
  208.    GrowMode := gfGrowHiX + gfGrowHiY;
  209.    DragMode := dmLimitLoX + dmLimitLoY;
  210.    SetLimit(MaxDim.X,MaxDim.Y);
  211. END;
  212.  
  213. CONSTRUCTOR TInterior.Load;
  214. VAR   i,j : INTEGER;
  215.       ok  : BOOLEAN;
  216.       B   : TDrawBuffer;
  217. BEGIN
  218.    TScroller.Load(S);
  219.    S.Read(AutoScroll,SIZEOF(AutoScroll));
  220.    S.Read(CurLoc,SIZEOF(CurLoc));
  221.    S.Read(MaxDim,SIZEOF(MaxDim))